/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo3791;

import eu.mpower.framework.management.patientmanagement.soap.GetPatientForPersonMessage;
import eu.mpower.framework.management.patientmanagement.soap.GetPatientsForUserMessage;
import eu.mpower.framework.management.patientmanagement.soap.GetPersonForUserMessage;
import eu.mpower.framework.management.patientmanagement.soap.GetProvidersForPatientMessage;
import eu.mpower.framework.management.patientmanagement.soap.GetRelationshipsForUserMessage;
import eu.mpower.framework.management.patientmanagement.soap.GetRelationshipsToUserMessage;
import eu.mpower.framework.management.patientmanagement.soap.Patient;
import eu.mpower.framework.management.patientmanagement.soap.PatientResponseMessage;
import eu.mpower.framework.management.patientmanagement.soap.PatientsResponseMessage;
import eu.mpower.framework.management.patientmanagement.soap.Person;
import eu.mpower.framework.management.patientmanagement.soap.PersonRelationship;
import eu.mpower.framework.management.patientmanagement.soap.PersonRelationshipsResponseMessage;
import eu.mpower.framework.management.patientmanagement.soap.PersonResponseMessage;
import eu.mpower.framework.management.patientmanagement.soap.Provider;
import eu.mpower.framework.management.patientmanagement.soap.ProviderType;
import eu.mpower.framework.management.patientmanagement.soap.ProvidersResponseMessage;
import eu.mpower.framework.security.types.soap.LoginStatus;
import eu.mpower.framework.security.types.soap.SecurityToken;
import eu.mpower.mpoweractivityservice.soap.AddActivityRequest;
import eu.mpower.mpoweractivityservice.soap.AddActivityResponse;
import eu.mpower.mpoweractivityservice.soap.Event;
import eu.mpower.mpoweractivityservice.soap.GetActivitiesForUserByDateWithAllRequest;
import eu.mpower.mpoweractivityservice.soap.GetActivitiesForUserByDateWithAllResponse;
import eu.mpower.mpoweractivityservice.soap.GetActivitiesForUserByDateWithGroupRequest;
import eu.mpower.mpoweractivityservice.soap.GetActivitiesForUserByDateWithGroupResponse;
import eu.mpower.mpoweractivityservice.soap.GetActivitiesForUserByDateWithIndividualResponse;
import java.util.GregorianCalendar;
import java.util.List;
import javax.swing.JPanel;
import java.awt.CardLayout;
import java.awt.Container;

/**
 *
 * @author Neozed
 */
public class testFrame extends javax.swing.JFrame {

    long userID = 0;
    Patient selectedPatient = null;
    //Person selectedPerson = null;
    Provider selectedProvider = null;
    SecurityToken secToken = null;
    
    boolean adminUI = false;
    
    /**
     * Creates new form testFrame
     */
    public testFrame() {
        initComponents();
        calendarPane.setViewportView(new CalendarDialog(this));
        JPanel panel = new JPanel();
        panel.setLayout(new java.awt.GridLayout(5,1));
        panel.add(new AppointmentPanel());
        panel.add(new AppointmentPanel());
        jScrollPane1.setViewportView(panel);
        dayPane.setViewportView(new AppointmentPanel());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        loginPanel = new javax.swing.JPanel();
        labelUsername = new javax.swing.JLabel();
        labelPassword = new javax.swing.JLabel();
        userName = new javax.swing.JTextField();
        loginButton = new javax.swing.JButton();
        passWord = new javax.swing.JTextField();
        subjectOfCarePanel = new javax.swing.JPanel();
        labelTime = new javax.swing.JLabel();
        labelDate = new javax.swing.JLabel();
        labelDayNight = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        appointmentsArea = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        calendarPane = new javax.swing.JScrollPane();
        dayPane = new javax.swing.JScrollPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });
        getContentPane().setLayout(new java.awt.CardLayout());

        loginPanel.setRequestFocusEnabled(false);

        labelUsername.setText("Brukernavn:");

        labelPassword.setText("Passord:");

        loginButton.setText("Logg inn");
        loginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout loginPanelLayout = new javax.swing.GroupLayout(loginPanel);
        loginPanel.setLayout(loginPanelLayout);
        loginPanelLayout.setHorizontalGroup(
            loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(loginPanelLayout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(loginPanelLayout.createSequentialGroup()
                        .addComponent(labelUsername)
                        .addGap(18, 18, 18)
                        .addComponent(userName, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(loginPanelLayout.createSequentialGroup()
                        .addComponent(labelPassword)
                        .addGap(35, 35, 35)
                        .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(loginButton)
                            .addComponent(passWord))))
                .addContainerGap(463, Short.MAX_VALUE))
        );
        loginPanelLayout.setVerticalGroup(
            loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(loginPanelLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelUsername)
                    .addComponent(userName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelPassword)
                    .addComponent(passWord, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(loginButton)
                .addContainerGap(145, Short.MAX_VALUE))
        );

        getContentPane().add(loginPanel, "login");

        labelTime.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
        labelTime.setText("9:00");

        labelDate.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        labelDate.setText("Tirsdag 8. Oktober 2013");

        labelDayNight.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/day.png"))); // NOI18N

        appointmentsArea.setEditable(false);
        appointmentsArea.setColumns(20);
        appointmentsArea.setRows(5);
        jScrollPane1.setViewportView(appointmentsArea);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setText("Dagens aktiviteter:");

        javax.swing.GroupLayout subjectOfCarePanelLayout = new javax.swing.GroupLayout(subjectOfCarePanel);
        subjectOfCarePanel.setLayout(subjectOfCarePanelLayout);
        subjectOfCarePanelLayout.setHorizontalGroup(
            subjectOfCarePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(subjectOfCarePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(subjectOfCarePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(subjectOfCarePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(subjectOfCarePanelLayout.createSequentialGroup()
                            .addComponent(labelTime)
                            .addGap(46, 46, 46)
                            .addComponent(labelDate))
                        .addComponent(jScrollPane1))
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(labelDayNight)
                .addGap(31, 31, 31))
        );
        subjectOfCarePanelLayout.setVerticalGroup(
            subjectOfCarePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(subjectOfCarePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(subjectOfCarePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(subjectOfCarePanelLayout.createSequentialGroup()
                        .addComponent(labelDayNight)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(subjectOfCarePanelLayout.createSequentialGroup()
                        .addGroup(subjectOfCarePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelTime)
                            .addComponent(labelDate))
                        .addGap(38, 38, 38)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)))
                .addContainerGap())
        );

        getContentPane().add(subjectOfCarePanel, "subjectOfCare");

        jPanel3.setPreferredSize(new java.awt.Dimension(747, 494));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(calendarPane, javax.swing.GroupLayout.DEFAULT_SIZE, 707, Short.MAX_VALUE)
            .addComponent(dayPane, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(calendarPane, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dayPane, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        getContentPane().add(jPanel3, "jPanel3");

        jMenu1.setText("File");

        jMenuItem1.setText("Exit");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        jMenuItem2.setText("Subject of care screen");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuItem3.setText("jMenuItem3");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem3);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void showThisPanel(String name) {
        Container container = getContentPane();
        CardLayout layout = (CardLayout)(container.getLayout());
        layout.show(container, name);
    }
    
    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
        Container container = getContentPane();
        CardLayout layout = (CardLayout)(container.getLayout());
        showThisPanel("subjectOfCare");
        //loginPanel.setVisible(false);
        //subjectOfCarePanel.setVisible(true);
        //jPanel3.setVisible(false);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // TODO add your handling code here:
        showThisPanel("jPanel3");
        //loginPanel.setVisible(false);
        //subjectOfCarePanel.setVisible(false);
        //jPanel3.setVisible(true);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:
        //showThisPanel("card3");
        jMenu2.setVisible(true);
        //subjectOfCarePanel.setVisible(false);
        //jPanel3.setVisible(false);
    }//GEN-LAST:event_formWindowActivated

    private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed
        // TODO add your handling code here:     
        String user = userName.getText().trim();
        String pwd = passWord.getText().trim();



        LoginStatus ls = authenticateUserPass(user, pwd);

        if (ls.getStatus().getResult() == 0) {
            userID = new Long(ls.getSecurityToken().getUserID()).longValue();
            secToken = ls.getSecurityToken();
            //logWindow.append("\nLogin ok:" + ls.getMessage() + " for user " + ls.getSecurityToken().getUserID());



            GetPersonForUserMessage gpfum = new GetPersonForUserMessage();
            gpfum.setSecurityToken(secToken);
            gpfum.setUserID(new Long(userID).longValue());

            PersonResponseMessage prm = getPersonForUser(gpfum);

            if (prm.getStatus().getResult() == 0) {
                appointmentsArea.append("\nGetPersonForUser ok: " 
                        + prm.getPerson().getGivenNames() + " " 
                        + prm.getPerson().getFamilyName() + " logged in as " 
                        + gpfum.getSecurityToken().getPrimaryRoleName());
    //delete            jLabel3.setText(prm.getPerson().getGivenNames());

            }

            //if this is a provider - get patients
            String primRole = secToken.getPrimaryRoleName();
            if (primRole.equals("HealthProfessional") || primRole.equals("Appointed GP"))  {
                //set the UI to be admin
                adminUI=true;
                
                selectedProvider = new Provider();
                selectedProvider.setPerson(prm.getPerson());
                ProviderType pt = new ProviderType(); //cannot really find more information about the provider...
                selectedProvider.setProviderType(pt);
                 
                GetPatientsForUserMessage patM = new GetPatientsForUserMessage();
                patM.setSecurityToken(secToken);
                patM.setUserID(new Long(userID).longValue());

                PatientsResponseMessage patRes = getPatientsForUser(patM);

                if (patRes.getStatus().getResult() == 0) {

                    List<Patient> patList = patRes.getPatients();

                    for (Patient p : patList) {
                        selectedPatient = p;
 /*                       logWindow.append("\nPatient found \n" 
                                + p.getPerson().getFamilyName() + " " 
                                + p.getPerson().getGivenNames() + " (" 
                                + p.getId() + ")");
*/
                    }

                }
            }//end if provider
            else {
                //we have a patient. 
                adminUI=false;
                
                //Get patient object
                GetPatientForPersonMessage perM = new GetPatientForPersonMessage();
                perM.setSecurityToken(secToken);
                perM.setPersonID(prm.getPerson().getId());
                
                PatientResponseMessage patM = getPatientForPerson(perM);
                
                if (patM.getStatus().getResult()==0) {
                    selectedPatient = patM.getPatient();
     //               appointmentsArea.append("\nFound patient: " + selectedPatient.getId() + " - " + selectedPatient.getPerson().getGivenNames());
                    
                }
                
                //get the providers
                GetProvidersForPatientMessage provM = new GetProvidersForPatientMessage();
                provM.setSecurityToken(secToken);
                provM.setPatientID(selectedPatient.getId());
                
                ProvidersResponseMessage provRes = getProvidersForPatient(provM);
                if (provRes.getStatus().getResult()==0) {
  //                  logWindow.append("\nFound providers: " + provRes.getProviders().size());
                    List<Provider> provList = provRes.getProviders();
                    for (Provider prov : provList) {
     /*                   logWindow.append("\nProvider " + prov.getId() + " - " 
                                + prov.getPerson().getGivenNames()   + " " 
                                + prov.getPerson().getFamilyName()   + " (" 
                                + prov.getProviderType().getProviderTypeName() + ")");
       */                 
                    
                    }
                            
                
                }
                
                //get other relationships
                GetRelationshipsForUserMessage relM = new GetRelationshipsForUserMessage();
                relM.setSecurityToken(secToken);
                relM.setUserID(userID); //assuming this is the patient's userID
                
                PersonRelationshipsResponseMessage relRes = getRelationshipsForUser(relM);
                
                if (relRes.getStatus().getResult()==0) {
                    //print the relationships
                    List<PersonRelationship> rList = relRes.getRelationships();
                    
                    for (PersonRelationship pr: rList) {
                    
     /*                   logWindow.append("\n: Found Relationship from: " + pr.getFromPerson().getFamilyName() 
                                + " to " + pr.getToPerson().getFamilyName() + " as " 
                                + pr.getRelationshipType().getRelationshipTypeName() );
       */                 
                    }
                
                }
                
                //get other relationships
                GetRelationshipsToUserMessage relTM = new GetRelationshipsToUserMessage();
                relTM.setSecurityToken(secToken);
                relTM.setUserID(userID); //assuming this is the patient's userID
                
                PersonRelationshipsResponseMessage relTRes = getRelationshipsToUser(relTM);
                
                if (relTRes.getStatus().getResult()==0) {
                    //print the relationships
                    List<PersonRelationship> rTList = relTRes.getRelationships();
                    
                    for (PersonRelationship pr: rTList) {
                    
   /*                     logWindow.append("\n: Found Relationship TO: " + pr.getFromPerson().getFamilyName() 
                                + " FROM " + pr.getToPerson().getFamilyName() + " as " 
                                + pr.getRelationshipType().getRelationshipTypeName() );
     */                   
                    }
                
                }
                showThisPanel("subjectOfCare");
                //loginPanel.setVisible(false);
                //subjectOfCarePanel.setVisible(true);
                //jPanel3.setVisible(false);
                
            }
           
            //GetActivitiesForUserByDateWithAllResponse getActivitiesForUserByDateWithAll(eu.mpower.mpoweractivityservice.soap.GetActivitiesForUserByDateWithAllRequest 
        GetActivitiesForUserByDateWithGroupRequest getA = new GetActivitiesForUserByDateWithGroupRequest();
        getA.setSecurityToken(secToken);
        if (adminUI) {
            getA.setPersonId(selectedProvider.getPerson().getId());
        }
        else {
            getA.setPersonId(selectedPatient.getPerson().getId());
        }
            
        
        GetActivitiesForUserByDateWithGroupResponse actRes = getActivitiesForUserByDateWithGroup(getA);
        
        if (actRes.getStatus().getResult()==0) {
            appointmentsArea.append("\nWe found " + actRes.getEvents().size() + " activities for this user" ); 
            List<Event> evList = actRes.getEvents();
            for (Event e: evList) {
                appointmentsArea.append("\nActivity: " + e.getName() + " - "
                        + e.getDescription() + " at "
                        + e.getStartDate());
            }
        
        }
        
        else {
            appointmentsArea.append("\nNo activities found");
        }
        }
    }//GEN-LAST:event_loginButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(testFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(testFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(testFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(testFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new testFrame().setVisible(true);
            }
        });
    }
    
    public void addActivity(GregorianCalendar date, String name, String description) {
        AddActivityRequest req = new AddActivityRequest();
        Event e = new Event();
        e.setName(name);
        e.setDescription(description);
        e.setStartDate(date.getTimeInMillis());
        req.setEvent(e);
        req.setSecurityToken(secToken);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea appointmentsArea;
    private javax.swing.JScrollPane calendarPane;
    private javax.swing.JScrollPane dayPane;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelDate;
    private javax.swing.JLabel labelDayNight;
    private javax.swing.JLabel labelPassword;
    private javax.swing.JLabel labelTime;
    private javax.swing.JLabel labelUsername;
    private javax.swing.JButton loginButton;
    private javax.swing.JPanel loginPanel;
    private javax.swing.JTextField passWord;
    private javax.swing.JPanel subjectOfCarePanel;
    private javax.swing.JTextField userName;
    // End of variables declaration//GEN-END:variables

    private static LoginStatus authenticateUserPass(java.lang.String username, java.lang.String password) {
        eu.mpower.framework.security.authentication.soap.AuthenticationWServiceService service = new eu.mpower.framework.security.authentication.soap.AuthenticationWServiceService();
        eu.mpower.framework.security.authentication.soap.PortTypeAuthenticationWService port = service.getAuthenticationWServicePort();
        return port.authenticateUserPass(username, password);
    }

    private static PersonResponseMessage getPersonForUser(eu.mpower.framework.management.patientmanagement.soap.GetPersonForUserMessage userIDmsg) {
        eu.mpower.framework.management.patientmanagement.soap.PatientManagement service = new eu.mpower.framework.management.patientmanagement.soap.PatientManagement();
        eu.mpower.framework.management.patientmanagement.soap.IPatientManagement port = service.getIPatientManagement();
        return port.getPersonForUser(userIDmsg);
    }

    private static PatientsResponseMessage getPatientsForUser(eu.mpower.framework.management.patientmanagement.soap.GetPatientsForUserMessage userIDmsg) {
        eu.mpower.framework.management.patientmanagement.soap.PatientManagement service = new eu.mpower.framework.management.patientmanagement.soap.PatientManagement();
        eu.mpower.framework.management.patientmanagement.soap.IPatientManagement port = service.getIPatientManagement();
        return port.getPatientsForUser(userIDmsg);
    }

    private static PatientResponseMessage getPatientDetails(eu.mpower.framework.management.patientmanagement.soap.GetPatientDetailsMessage patientid) {
        eu.mpower.framework.management.patientmanagement.soap.PatientManagement service = new eu.mpower.framework.management.patientmanagement.soap.PatientManagement();
        eu.mpower.framework.management.patientmanagement.soap.IPatientManagement port = service.getIPatientManagement();
        return port.getPatientDetails(patientid);
    }

    private static PatientResponseMessage getPatientForPerson(eu.mpower.framework.management.patientmanagement.soap.GetPatientForPersonMessage personIDmsg) {
        eu.mpower.framework.management.patientmanagement.soap.PatientManagement service = new eu.mpower.framework.management.patientmanagement.soap.PatientManagement();
        eu.mpower.framework.management.patientmanagement.soap.IPatientManagement port = service.getIPatientManagement();
        return port.getPatientForPerson(personIDmsg);
    }

    private static ProvidersResponseMessage getProvidersForPatient(eu.mpower.framework.management.patientmanagement.soap.GetProvidersForPatientMessage patientIDmsg) {
        eu.mpower.framework.management.patientmanagement.soap.PatientManagement service = new eu.mpower.framework.management.patientmanagement.soap.PatientManagement();
        eu.mpower.framework.management.patientmanagement.soap.IPatientManagement port = service.getIPatientManagement();
        return port.getProvidersForPatient(patientIDmsg);
    }

    private static PersonRelationshipsResponseMessage getRelationshipsForUser(eu.mpower.framework.management.patientmanagement.soap.GetRelationshipsForUserMessage userIDmsg) {
        eu.mpower.framework.management.patientmanagement.soap.PatientManagement service = new eu.mpower.framework.management.patientmanagement.soap.PatientManagement();
        eu.mpower.framework.management.patientmanagement.soap.IPatientManagement port = service.getIPatientManagement();
        return port.getRelationshipsForUser(userIDmsg);
    }

    private static PersonRelationshipsResponseMessage getRelationshipsToUser(eu.mpower.framework.management.patientmanagement.soap.GetRelationshipsToUserMessage userIDmsg) {
        eu.mpower.framework.management.patientmanagement.soap.PatientManagement service = new eu.mpower.framework.management.patientmanagement.soap.PatientManagement();
        eu.mpower.framework.management.patientmanagement.soap.IPatientManagement port = service.getIPatientManagement();
        return port.getRelationshipsToUser(userIDmsg);
    }

    private static GetActivitiesForUserByDateWithAllResponse getActivitiesForUserByDateWithAll(eu.mpower.mpoweractivityservice.soap.GetActivitiesForUserByDateWithAllRequest parameters) {
        eu.mpower.mpoweractivityservice.soap.ActivityWebService_Service service = new eu.mpower.mpoweractivityservice.soap.ActivityWebService_Service();
        eu.mpower.mpoweractivityservice.soap.ActivityWebService port = service.getActivityWebServicePort();
        return port.getActivitiesForUserByDateWithAll(parameters);
    }

    private static AddActivityResponse addActivity(eu.mpower.mpoweractivityservice.soap.AddActivityRequest parameters) {
        eu.mpower.mpoweractivityservice.soap.ActivityWebService_Service service = new eu.mpower.mpoweractivityservice.soap.ActivityWebService_Service();
        eu.mpower.mpoweractivityservice.soap.ActivityWebService port = service.getActivityWebServicePort();
        return port.addActivity(parameters);
    }

    private static GetActivitiesForUserByDateWithIndividualResponse getActivitiesForUserByDateWithIndividual(eu.mpower.mpoweractivityservice.soap.GetActivitiesForUserByDateWithIndividualRequest parameters) {
        eu.mpower.mpoweractivityservice.soap.ActivityWebService_Service service = new eu.mpower.mpoweractivityservice.soap.ActivityWebService_Service();
        eu.mpower.mpoweractivityservice.soap.ActivityWebService port = service.getActivityWebServicePort();
        return port.getActivitiesForUserByDateWithIndividual(parameters);
    }

    private static GetActivitiesForUserByDateWithGroupResponse getActivitiesForUserByDateWithGroup(eu.mpower.mpoweractivityservice.soap.GetActivitiesForUserByDateWithGroupRequest parameters) {
        eu.mpower.mpoweractivityservice.soap.ActivityWebService_Service service = new eu.mpower.mpoweractivityservice.soap.ActivityWebService_Service();
        eu.mpower.mpoweractivityservice.soap.ActivityWebService port = service.getActivityWebServicePort();
        return port.getActivitiesForUserByDateWithGroup(parameters);
    }
}
